package com.example.backend_422.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.backend_422.common.Result;
import com.example.backend_422.entity.Notify;
import com.example.backend_422.mapper.NotifyMapper;
import com.example.backend_422.service.NotifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NotifyServiceImpl extends ServiceImpl<NotifyMapper, Notify> implements NotifyService {
    @Autowired
    private NotifyMapper notifyMapper;

    public Result getAllNotify() {
        return Result.succ(notifyMapper.selectList(null));
    }


    public Result deleteById(Integer id) {
        UpdateWrapper<Notify> wrapper = new UpdateWrapper<>();
        wrapper.eq("notify_id",id);
        return Result.succ(notifyMapper.delete(wrapper));

    }

    public Result addNotify(String title, String content) {
        Notify notify = new Notify();
        notify.setTitle(title);
        notify.setContent(content);
        notifyMapper.insert(notify);
        return Result.succ(notify);
    }
}
